package com.mall.order.biz.handler;

import com.mall.order.biz.context.CreateOrderContext;
import com.mall.order.biz.context.TransHandlerContext;
import com.mall.order.services.OrderQueryServiceImpl;
import com.mall.shopping.ShoppingCart1;
import com.mall.shopping.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *  ciggar
 * create-date: 2019/8/1-下午5:05
 * 将购物车中的缓存失效
 */
@Slf4j
@Component
public class ClearCartItemHandler extends AbstractTransHandler {

    @Autowired
    RedissonClient redissonClient;

    @Reference
    ShoppingCartService shoppingCartService;

    @Autowired
    OrderQueryServiceImpl orderQueryService;

    //是否采用异步方式执行
    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {

        CreateOrderContext contexts = (CreateOrderContext)context;
        List<Long> longs = orderQueryService.checkItemByOrderId(contexts.getOrderId());
        shoppingCartService.deleteSomeCart(contexts.getUserId(),longs);

        return true;
    }
}
